import React, { useState } from 'react'
import { FileButton } from 'rc-easyui';
export default function File(props) { 
  const [uploadname,setupload] = useState('')
  const [FileName,setName] = useState('')
  function success(xhr){
    setupload(xhr.files[0].name)
    setName(xhr.xhr.response)
    props.showFile(xhr.xhr.response) 
  }
  return (
    <div className="upload">
      <p>选择头像:</p>
      <FileButton name='avatar'  onSuccess={success} url={'users/file'} style={{ width: 100 }} >选择文件</FileButton>
      { FileName ?< img src={`/images/${FileName}`} alt=""/> : '暂无选择'} 
      <p>当前选择: {uploadname ? uploadname + '(上传成功)' : '暂无选择'}</p>
    </div>
  )
}
